#include "regx52.h"
#include "STC89C5xRC-rdp.h"
#include "datatype.h"
#include "bit.h"
#include "delay.h"

#include "uart.h"
#include "key_4_by_4.h"

void SendNumber(void)
{
	uint_8 cmd = keyboard_4_by_4();

	if (cmd == KEY_INVALID) {
		return;
	} else {
		switch(cmd) {
			case KEY_0:
				send_msg("0");
				break;
			case KEY_1:
				send_msg("1");
				break;
			case KEY_2:
				send_msg("2");
				break;
			case KEY_3:
				send_msg("3");
				break;
			case KEY_4:
				send_msg("4");
				break;
			case KEY_5:
				send_msg("5");
				break;
			case KEY_6:
				send_msg("6");
				break;
			case KEY_7:
				send_msg("7");
				break;
			case KEY_8:
				send_msg("8");
				break;
			case KEY_9:
				send_msg("9");
				break;
			case KEY_ASTERISK:
				send_msg("*");
				break;
			case KEY_HASH:
				send_msg("#");
				break;
			case KEY_A:
				send_msg("A");
				break;
			case KEY_B:
				send_msg("B");
				break;
			case KEY_C:
				send_msg("C");
				break;		
			case KEY_D:
				send_msg("D");
				break;
			default:
				break;
		}
	}
}

void setup(void)
{
	/* put your setup code here, to run once: */
	uart_init(BAUD_RATE_9600);
}

void main(void)
{
	setup();

	while (TRUE) {
		/* put your main code here, to run repeatedly: */
		ES  = TURN_OFF;
		EA  = TURN_OFF;
		SendNumber();
		delay_xms(100);
	}
}